package com.wjl.shop.controller;

import com.wjl.shop.entity.Dealer;
import com.wjl.shop.service.DealerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 经销商表(Dealer)表控制层
 *
 * @author makejava
 * @since 2021-10-07 14:07:23
 */
@RestController
@RequestMapping("dealer")
@CrossOrigin
public class DealerController {
    /**
     * 服务对象
     */
    @Resource
    private DealerService dealerService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Dealer selectOne(Integer id) {
        return this.dealerService.queryById(id);
    }


    /**
     * 经销商登录
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/login")
    public Map<String,Object> dealerLogin(String username,String password){
        return  this.dealerService.dealerLogin(username,password);
    }

    /**
     * 查找关联经销商
     * @param dealerName
     * @return
     */
    @GetMapping("/findRelatedDealer")
    public Map<String,Object> findRelatedDealer(String dealerName){
        return dealerService.findByName(dealerName);
    }


    /**
     *查询表中是否有对应信息的用户
     * @param dealer
     * @return 是否成功的信息
     */
    @GetMapping("isName")
    public Map<String, Object> isName(Dealer dealer){
        return this.dealerService.isName(dealer);
    }


    /**
     * 查询经销商信息
     * @param dealer
     * @return 返回是否成功的信息和数据
     */
    @GetMapping("queryBoss")
    public Map <String, Object> queryBoss(Dealer dealer){
        return this.dealerService.queryBoss(dealer);
    }

    /**
     * 插入经销商信息
     * @param dealer
     * @return 是否成功的信息
     */
    @PostMapping("createDealer")
    public Map<String,Object> createDealer(Dealer dealer){
        return this.dealerService.createDealer(dealer);
    }


    /**
     * 删除经销商信息
     * @param dealer
     * @return 是否成功的信息
     */
    @GetMapping("deleteDealer")
    public Map <String, Object> deleteDealer(Dealer dealer){
        return this.dealerService.deleteDealer(dealer);
    }


    /**
     * 根据登录经销商名称查询账号信息
     * @param username
     * @return
     */
    @GetMapping("findAccountInfo")
    public Map<String,Object> findAccountInfo(String username){
        return this.dealerService.findAccountInfo(username);
    }


    /**
     * 更新密码模块
     * @param username  用户名
     * @param password  原密码
     * @param newPassword   新密码
     * @param confirm   确认新密码
     * @return
     */
    @GetMapping("checkAndUpdatePassword")
    public Map<String,Object> checkPassword(String username,String password,String newPassword,String confirm){
        return this.dealerService.checkPassword(username, password,newPassword,confirm);
    }
    /**
     * 重置密码
     * @param dealer
     * @return是否成功
     */
    @GetMapping("rePassword")
    public Map <String, Object> rePassword(Dealer dealer){
        return this.dealerService.rePassword(dealer);
    }

    /**
     * 关联经销商信息
     * @param dealer
     * @return 返回是否成功
     */
    @GetMapping("relationDealer")
    public Map <String, Object> relationDealer(Dealer dealer){
        return this.dealerService.relationDealer(dealer);
    }
    /**
     * 更改经销商信息
     *
     * @param dealer
     * @return是否成功
     */
    @GetMapping("updateDealer")
    public Map <String, Object> updateDealer(Dealer dealer){
        return this.dealerService.updateDealer(dealer);
    }
}
